//
// Created by LiuYou on 2021/5/7.
//

#ifndef HIGHPERFORMANCELINUXSERVERPROGRAMMING_LINUX_CLIENTDATA_HPP
#define HIGHPERFORMANCELINUXSERVERPROGRAMMING_LINUX_CLIENTDATA_HPP


#include <netinet/in.h>
#include <string>

namespace Server07 {
    constexpr int getBufferSize() {
        return 64;
    }

    class ClientData {
        // TODO 注意: 私聊功能这里需要加一个字段(字符串)与fd进行配对。
    public:
        sockaddr_in sockAddrIn{};
        char* writeBuffer{};
//        char writeBuffer[getBufferSize()]{};
        char buffer[getBufferSize()]{};

    public:
        std::string userName;

    public:
        char ip[17]{};
        char* ptrIp;

    public:
        ClientData();

    public:
        const sockaddr_in& getSockAddrIn() const;

        void setSockAddrIn(const sockaddr_in& sockAddrIn);

//        char* getWriteBuffer() const;
//
//        void setWriteBuffer(char* writeBuffer);




        const char* getBuffer() const;

        char* getBuffer();

    public:
        const std::string& getUserName() const;

        void setUserName(const std::string& userName);

    public:
        const char* getIp();
    };

    // TODO 注意: 这里加上 static之后有警告
//    In file included from Server.cpp:15:
//    ClientData.hpp:36:16: warning: ‘int Server::setNonBlocking(int)’ used but never defined
//    static int setNonBlocking(int fd);
//    ^~~~~~~~~~~~~~
    int setNonBlocking(int fd);
}


#endif //HIGHPERFORMANCELINUXSERVERPROGRAMMING_LINUX_CLIENTDATA_HPP
